import 'package:flutter_repository/repository/request_state.dart';
import 'package:get/get.dart';
import 'package:example_app/mapper/home_data_mapper.dart';
import 'package:example_app/repository/wan_repository.dart';

class HomeLogic extends GetxController {
  final Rx<Resource<HomeDataMapper>> homeData =
      Resource<HomeDataMapper>.loading().obs;

  late final WanRepository repository = GetInstance().find();

  @override
  void onInit() {
    super.onInit();
    loadHomeData();
  }

  Future<void> loadHomeData() async {
    //从仓储获取数据，更新到状态
    await for (var data in repository.homeData()) {
      homeData.value = data;
    }
  }
}
